home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
dtk_demo.zip
/
FILETYPE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-12
|
2KB
|
94 lines
/* FILETYPE.C
* checks multiple files for filetype
* last mod.: 15-SEP-91
*/
#include <STDIO.H>
#include <FCNTL.H>
#include <SYS\TYPES.H>
#include <SYS\STAT.H>
#include <IO.H>
#include <STDLIB.H>
#include <STRING.H>
#include <L_FILE.H>
#include <L_DIR.H>
char *usage = "\nUse: FILETYPE file_spec";
char path[_MAX_PATH_];
char drive[_MAX_DRIVE_];
char dir[_MAX_PATH_];
char file[_MAX_FILE_];
/*----------------------------*/
void main(int argc,char *argv[])
{
int i, n, err_flag, result;
File *files;
if ( argc < 2 )
{
printf(usage);
exit(0);
}
strupr(argv[1]);
split_path(argv[1],drive,dir,NULL,NULL);
#if 0
int read_directory_f(Str_ptr file_spec, Str_ptr attr_spec,
File far *files);
int read_directory(Str_ptr file_spec, Str_ptr attr_spec,
File *files);
#endif
n = get_input_output_files(argc,argv,&files,NULL,NULL,&err_flag);
/* this function allocates n*sizeof(File) bytes from
* the near heap to hold the File array
*/
#if 0
n = read_directory(argv[1],NULL,files);
*/
#endif
if ( err_flag )
{
switch ( err_flag )
{
case -2: printf("Invalid command line parameters.\n"); break;
case -3: printf("Out of near heap space.\n"); break;
case -4: break; /* ignore this error condition */
default: printf("Unknown error.\n");
}
}
else if ( !n )
printf("No files found matching %s.\n",argv[1]);
else
{
printf("Files matching %s: %d\n",argv[1],n);
for ( i=0; i<n; i++ )
{
printf("%12s: ",files[i].name);
make_path(path,drive,dir,files[i].name);
switch ( result = file_type(path) )
{
case 2: printf("text file.\n"); break;
case 3: printf(".EXE file.\n"); break;
case 4: printf(".OBJ file.\n"); break;
case 5: printf("PKZIP file.\n"); break;
case -3: printf("open error.\n"); break;
case -4: printf("read error.\n"); break;
case -5: printf("empty file.\n"); break;
case -6: printf("file consists of 1 or 2 bytes.\n"); break;
case -7: printf("null byte found.\n"); break;
case -8: printf("non-text byte found.\n"); break;
default: printf("unknown error (%d).\n",result);
}
}
}
}